package main

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
	//"time"
)

func main() {
	db, err := sql.Open("mysql", `lwj:Ryt5mOTt@tcp(192.168.1.61:3306)/test?charset=utf8`)
	checkErr(err)

	//查询数据
	rows, err := db.Query("SELECT * FROM user")
	checkErr(err)

	for rows.Next() {
		var id int64
		var data []byte
		err = rows.Scan(&id, &data)
		checkErr(err)
		fmt.Printf("id=%d\n", id)
		fmt.Printf("data=%s\n", data)
	}

	db.Close()
}

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}
